*******************************************************************************
* Figure A.2(McCrary)
*******************************************************************************

use  "Data_temp/turnout.dta", clear

gen rel_age=.
gen elec=.
foreach x in 1992 1997 2001 2005 2010 2015 2017 {
	replace rel_age=age`x' if inrange(age`x',-24,23) & rel_age==.
	replace elec=`x' if inrange(age`x',-24,23) & elec==.
	}

duplicates drop pidp rel_age elec, force	
sum rel_age	


DCdensity rel_age if inrange(rel_age,-24,23),  breakpoint(0) generate(Xj Yj r0 fhat se_fhat) b(1)
dis round(r(theta)/r(se),.001)

gen hi= fhat + 1.96*se_fhat
gen lo = fhat - 1.96*se_fhat

twoway (scatter Yj Xj, msymbol(circle_hollow) mcolor(gray)) (line fhat r0 if r0 < 0, lcolor(black) lwidth(medthick)) ///
(line fhat r0 if r0 > 0, lcolor(black) lwidth(medthick)) (line hi r0 if r0 < 0, lcolor(black) lwidth(vthin)) ///
(line lo r0 if r0 < 0, lcolor(black) lwidth(vthin)) (line hi r0 if r0 > 0, lcolor(black) lwidth(vthin)) ///
(line lo r0 if r0 > 0, lcolor(black) lwidth(vthin)), xline(0, lcolor(black)) legend(off) ///
ylabel(0(0.006)0.03) xl(-24(6)24)  xt("Relative age in months to cut-off")	
graph export "Figures/a_fg1.eps", replace